#include <51func.h>
int main(int argc, char *argv[])
{
    int fds[2];
    pipe(fds); // 子 --> 父
    if(fork()){
        close(fds[1]);
        //close(fds[0]); // 父进程先关闭
        sleep(5);
        printf("sleep over!\n");
        char buf[4096] = {0};
        ssize_t sret = read(fds[0],buf,sizeof(buf));
        printf("sret = %ld\n", sret);
        int wstatus;
        wait(&wstatus);
        if(WIFSIGNALED(wstatus)){
            printf("signaled, num = %d\n", WTERMSIG(wstatus));
        }
    }
    else{
        close(fds[0]);
        //sleep(5);
        //printf("sleep over\n");
        //write(fds[1],"hello",5);
       // sleep(2);
       // int cnt = 0;
       // char buf[4096] = {0};
       // while(1){
       //     write(fds[1],buf,sizeof(buf));
       //     printf("cnt = %d\n", cnt++);
       // }
        close(fds[1]);
        while(1){
            sleep(1);
        }
    }
    return 0;
}

